package com.sap.mobile.maf.samples.android.mafprovisioningsample;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class SampleTabContent2 extends Activity implements SampleTabContent.DataListener {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.tab2_layout);
		Button btn = (Button) findViewById(R.id.navButton);
		SampleTabContent.registerForData(this);
		btn.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v){
				Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("google.navigation:q="+SampleTabContent.getAddressFormed()));
				startActivity(i);
				
			}
		});
		
		Button btn2 = (Button) findViewById(R.id.mapButton);
		btn2.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v){
				String uri = "https://maps.google.com/maps?q="+SampleTabContent.getAddressFormed();
				Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
				intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
				startActivity(intent);
				
			}
		});
		onDataReceived(SampleTabContent.isDataReceived());
	}

	@Override
	public void onDataReceived(boolean dataReceived) {
		findViewById(R.id.navButton).setEnabled(dataReceived);
		findViewById(R.id.mapButton).setEnabled(dataReceived);
	}
}
